package com.ruoyi.core.exception;


import com.ruoyi.core.constant.Constant;
import org.apache.commons.lang3.StringUtils;


/**
 * 所有异常基类
 *
 * @author wanghao
 */
public abstract class BaseException extends RuntimeException {

    protected Integer code;
    protected String message;

    public BaseException(Integer code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
        if (StringUtils.isEmpty(message) && cause != null) {
            this.message = cause.getMessage();
        }
    }

    public BaseException(Integer code, String message) {
        this(code, message, null);
    }

    public BaseException(String message) {
        this(Constant.CODE_FAIL, message, null);
    }

    public BaseException(Throwable cause) {
        this(Constant.CODE_FAIL, cause.getMessage(), cause);
    }

    public BaseException(String message, Throwable cause) {
        this(Constant.CODE_FAIL, message, cause);
    }

    @Override
    public String getMessage() {
        return message;
    }

    public Integer getCode() {
        return code;
    }

}
